package com.sdkteam.MainMenu;

import android.view.Display;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class ScreenFixing  {
	public static int LINEAR_LAYOUT=1;
	public static int RELATIVE_LAYOUT=2;
	public int WIDTH_DEFAULT=480;
	public int HEIGHT_DEFAULT=320 ;
	public int WIDTH;
	public int HEIGHT;
	public float rateWidth;
	public float rateHeight;
	@SuppressWarnings("deprecation")
	public ScreenFixing(Display d){
		this.WIDTH=d.getWidth();
		this.HEIGHT=d.getHeight();
		this.rateWidth=(float) (WIDTH*1.0/WIDTH_DEFAULT);
		this.rateHeight=(float) (HEIGHT*1.0/HEIGHT_DEFAULT);
	}
	//resize View
	public void resizeView(View view,int typeOfParentLayout){
		if(typeOfParentLayout==RELATIVE_LAYOUT){
			RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
			//resize with,height
				if(layoutParams.width>0){
					layoutParams.width=(int)(layoutParams.width*rateWidth);
				}
				if(layoutParams.height>0){
					layoutParams.height=(int)(layoutParams.height*rateHeight);
				}
			//resize margin
				RelativeLayout.LayoutParams marginDefault = (RelativeLayout.LayoutParams) view.getLayoutParams();
				int top =marginDefault.topMargin;
				int left=marginDefault.leftMargin;
				int right=marginDefault.rightMargin;
				int bottom=marginDefault.bottomMargin;
				layoutParams.setMargins((int) (left*rateWidth), (int) (top*rateHeight),(int) (right*rateWidth),(int) (bottom*rateHeight));
			//
			view.setLayoutParams(layoutParams);
		}else if(typeOfParentLayout==LINEAR_LAYOUT) {
			LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) view.getLayoutParams();
			//resize with,height
				if(layoutParams.width>0){
					layoutParams.width=(int)(layoutParams.width*rateWidth);
				}
				if(layoutParams.height>0){
					layoutParams.height=(int)(layoutParams.height*rateHeight);
				}
			//resize margin
				LinearLayout.LayoutParams marginDefault = (LinearLayout.LayoutParams) view.getLayoutParams();
				int top =marginDefault.topMargin;
				int left=marginDefault.leftMargin;
				int right=marginDefault.rightMargin;
				int bottom=marginDefault.bottomMargin;
				layoutParams.setMargins((int) (left*rateWidth), (int) (top*rateHeight),(int) (right*rateWidth),(int) (bottom*rateHeight));
			//
			view.setLayoutParams(layoutParams);
		}
		
	}
	
}
